$(window).load(function () {
	$(window).resize(function(){
		addControlZoombar();
	});

	$("#buildingInfo").hide();

	$("#addNewRow").click(function() {
		
		var copyRow = $(this).parent().parent();
		alert(copyRow.html());		
		$(this).parent().parent().after('<tr><td height="37" class="tdfffbff LP20 font12B_4f4f4f">제목/내용</td><td class="line_e7e7e7 LP20"><input name="name" style="width:80px" class="input" type="text" value="'+$('#name').val()+'"/><input name="description" style="width:80px" class="input" type="text" value="'+$('#description').val()+'"/><span class="font11_ff6d00"> (각 50콘트)</span></td></tr>');
		//$("#umj_building_infos > input[name="description"]").val("");
		$('#name').val("");
		$('#description').val("");
		
	});

	
	$("#submitBtn").click(function() {
		$("#umj_building_infos").submit();
	});

	$("#resetBtn").click(function() {
		$("#umj_building_infos").reset();
	});

	var map = getInitializedMap(lonlat);
	
	var wms_layers = map.getLayersByClass('OpenLayers.Layer.WMS');
	var wms = wms_layers[0];

	var wmsRequestStringOptions = {
	        REQUEST: "GetFeatureInfo",
	        EXCEPTIONS: "application/vnd.ogc.se_xml",
	        BBOX: wms.map.getExtent().toBBOX(),
	        X: 0,
	        Y: 0,
			INFO_FORMAT: 'text/plain', // 'text/plain', 'application/vnd.ogc.gml',
	        QUERY_LAYERS: 'umanji:building', // wms.params.LAYERS, 다 가져올 경우
	        WIDTH: wms.map.size.w,
	        HEIGHT: wms.map.size.h,
	        FORMAT: 'rss'}

    var building_mgt_sn_pattern=/\s(\d){25}\s/g;
	var orgAtrrHref = $("#updateLink").attr('href');

	// 드래그 레이어 등록 및 이벤트 처리 
    var dragFeature = new OpenLayers.Control.DragFeature(layer);
    dragFeature.onComplete = function(layer, pixel) {
    	lonlat = map.getLonLatFromViewPortPx(pixel);

        wmsRequestStringOptions['BBOX'] = wms.map.getExtent().toBBOX();
        wmsRequestStringOptions['WIDTH'] = wms.map.size.w;
        wmsRequestStringOptions['HEIGHT'] = wms.map.size.h;
    	wmsRequestStringOptions['X'] = pixel.x;
        wmsRequestStringOptions['Y'] = pixel.y;
        var url =  wms.getFullRequestString(wmsRequestStringOptions);

        $.get('/umanji_dev/umj/util/getWmsQueryPage?' + url.split("?")[1], function(data) {
    		var building_mgt_sn = data.match(building_mgt_sn_pattern);
    		var building_no = $.trim(new String(building_mgt_sn));
    		$.getJSON('info/' + building_no, function(data) {
    			$("#address").text(data['buildingAddress']);
    			$("#updateLink").attr('href', orgAtrrHref + building_no);
    			// alert(data['buildingName']);
    			// alert(data['buildingAddress']);
    			// alert(data['buildingOldAddress']);
    			$("#buildingInfo").show("slow");
    			$("#selectMapMsg").hide();
    		});
		});

    };
	map.addControl(dragFeature);
    dragFeature.activate();

	// addControlZoombar();

	// 마우스 클릭 시 발생 이벤트 처리
    map.events.register('click', map, function (e) {
    	lonlat = map.getLonLatFromViewPortPx(e.xy);

        OpenLayers.Util.getElement('nodeList').innerHTML = "Loading... please wait...";

        wmsRequestStringOptions['BBOX'] = wms.map.getExtent().toBBOX();
        wmsRequestStringOptions['WIDTH'] = wms.map.size.w;
        wmsRequestStringOptions['HEIGHT'] = wms.map.size.h;
        wmsRequestStringOptions['X'] = e.xy.x;
        wmsRequestStringOptions['Y'] = e.xy.y;
        var url =  wms.getFullRequestString(wmsRequestStringOptions);
    	// cross domain 문제로 인해 YQL로 대체함 2010년 4월 16일
    	// OpenLayers.loadURL(url, '', this, setHTML);

        $.get('/umanji_dev/umj/util/getWmsQueryPage?' + url.split("?")[1], function(data) {
    		var building_mgt_sn = data.match(building_mgt_sn_pattern);
    		var building_no = $.trim(new String(building_mgt_sn));
    		$.getJSON('info/' + building_no, function(data) {
    			$("#address").text(data['buildingAddress']);
    			$("#updateLink").attr('href', orgAtrrHref + building_no);
    			// alert(data['buildingName']);
    			// alert(data['buildingAddress']);
    			// alert(data['buildingOldAddress']);
    			$("#buildingInfo").show("slow");
    			$("#selectMapMsg").hide();
    		});
		});

        OpenLayers.Event.stop(e);
    });
});
// BD_MGT_SN = 1144011000100400051020214 RD_MGT_SN = P11440002497 EQB_MGT_SN = null BD_NM = 박여인숙 BD_ENG_NM = null BD_STS_CM = null BD_KD = 06999 BD_IN_SE = M PRECISE_SE = 3 DET_BD_NM = null ZIP_CL = 121-806 MT_YN = 0 UP_YMD = 20080806 WRK_MGT_SN = A11440080703000123 ANN_YN = 1 ANN_YMD = 20080303 ANN_DE = null NOTICE_YMD = null RESULT_SE = null ANN_SE = null EMD_CD = 1144011000 UDRT_YN = 0 BD_MA_SN = 34 BD_SB_SN = 0 LNDN_MA_SN = 40 LNDN_SB_SN = 51 ABV_FL_CNT = 2 UDR_FL_CNT = 0 RN_MGT_SN = null BD_MK_YMD = null UPDATE_YMD = null TRS_YMD = null the_geom = [GEOMETRY (MultiPolygon) with 5 points] CODE = null 